package com.see.client;

import java.util.HashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.swing.table.TableModel;

import com.see.domain.MessegeParser;
import com.see.domain.Order;
import com.see.domain.OrderServise;
import com.see.domain.Protocol;
import com.see.exception.MessegeFeedException;

public class FilledOrderListener implements Listener {

	TradingClientImpl tradingClient;
	OrderTableModel orderTableModel;
	public FilledOrderListener(TradingClientImpl tradingClient) {
		this.tradingClient = tradingClient;
	}
	
	
	public FilledOrderListener(TradingClientImpl tradeingclient,
			OrderTableModel orderTableModel) {
		this.tradingClient = tradingClient;
		this.orderTableModel = orderTableModel;
	}


	@Override
	public void notificate(HashMap<String, String> paramMap) throws MessegeFeedException {
		String cmd = paramMap.get(MessegeParser.MsgFields.TYPEMSG.name());
		if(cmd.equals(Protocol.FILLORDER_FIELD)){
			Order order = OrderServise.createMatchOrderFromMessege(paramMap);
			if(!orderTableModel.updateOrder(order)){
				orderTableModel.addOrder(order);
			}
		}
	}
	
	@Override
	public void waitForComplete() {
	}

}
